import storejs from '@/utils/storejs';
import {userKeys, hasLogin} from '@/utils/authUtils.js';

const keys = userKeys;

// 用户状态
const state = {
    //用户信息
    userInfo: storejs.get(keys.userInfo),
	
	//bgm是否停止播放
    bgmPaused: true,
	// 默认背景音乐
    bgmIndex: storejs.get("bgmIndex") || 0,
}


const getters = {

}

const mutations = {
    setUserInfo(state, userInfo){
        state.userInfo = userInfo;
        storejs.set(keys.userInfo, userInfo);
    },
    setBgmPaused(state, bgmPaused){
        state.bgmPaused = bgmPaused;
    },
	/**
	 * 设置关卡
	 */
    setPass(state, pass=1){
        state.userInfo.pass = pass;
		storejs.set(keys.userInfo, state.userInfo);
    },
	/**
	 * 设置金币
	 */
    setGold(state, gold=0){
        state.userInfo.gold = gold;
		storejs.set(keys.userInfo, state.userInfo);
    },
	/**
	 */
    setBgmIndex(state, index=0){
        state.bgmIndex = index;
		storejs.set("bgmIndex", index);
    },
}

const actions = {
    /**
     * 登录
     */
    login(context, formData){
		
    },
    /**
     * 注销登录
     */
    logout(context){
       
    },
    /**
     * 获取个人信息
     */
    getUserInfo(context){
        
    },
};


export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}
